<admintpl file="header" />
</head>
<body class="J_scroll_fixed">
	<div class="wrap J_check_wrap">
		<ul class="nav nav-tabs">
			<li><a href="{:U('Games/index')}">赛程列表</a></li>
			<li class="active"><a href="{:U('Games/add')}">添加赛程</a></li>
		</ul>
<script type="text/javascript">
var threeSelectData={
<php>
	foreach($gameinfos as $val){
		$name = $val['game_name'];
		$id = $val['id'];
		echo '"'.$name.'":{';
		echo 'val:"'.$id.'",';
			echo 'items:{';
				foreach($gameteamlinks as $v){
					$cur_group = $v['cur_group'];
					$gameid = $v['game_id'];
					if($id == $gameid){
						echo '"'.$cur_group.'":{"val":"'.$cur_group.'"},';
					}
				}
			echo '},';
		echo "},";
	}
</php>
};
var defaults = {
	s1:'mainselect',
	s2:'midselect',
};

$(function(){
	threeSelect(defaults);
});

function threeSelect(config){
	var $s1=$("#"+config.s1);
	var $s2=$("#"+config.s2);
	var v1=config.v1?config.v1:null;
	var v2=config.v2?config.v2:null;
	$.each(threeSelectData,function(k,v){
		appendOptionTo($s1,k,v.val,v1);
	});
	
	$s1.change(function(){
		$s2.html("");
		if(this.selectedIndex==-1)
		return;
		
		var s1_curr_val = this.options[this.selectedIndex].value;
		
		$.each(threeSelectData,function(k,v){
			if(s1_curr_val==v.val){
				if(v.items){
					$.each(v.items,function(k,v){
						appendOptionTo($s2,k,v.val,v2);
					});
				}
			}
		});
	
		if($s2[0].options.length==0){
			appendOptionTo($s2,"...","",v2);
		}
		
		$s2.change();
		
	}).change();
	
	function appendOptionTo($o,k,v,d){

		var $opt=$("<option>").text(k).val(v);
		
		if(v==d){
			$opt.attr("selected", "selected")
		}
		$opt.appendTo($o);
	}
	
}
</script>
<style type="text/css">
.radio, .checkbox {
width: 80px;
float: left;
}
</style>
	<form name="myform" id="myform" action="{:u('Games/vsteam')}" method="post" class="form-horizontal J_ajaxForms" enctype="multipart/form-data">
	<div class="col-auto">
		<div class="table_full">
		  <table class="table table-bordered">
		    <tr>
		      <th>赛事</th>
		      <td><select id="mainselect" name="game_id"></select></td>
		    </tr>
		    <tr>
		      <th>分组</th>
		      <td><select id="midselect" name="cur_group"></select></td>
		    </tr>
		    <tr>
		      <th>比赛类型</th>
		      <td>
	            <span class="switch_list cc">
            	<foreach name="groups" item="group">
					<label class="radio"><input type="radio" name="match_group" value="{$group.id}"><span>{$group.name}</span></label>
		        </foreach>
			 	</span>
		      </td>
		    </tr>
		  </table>
		</div>
	</div>
	<div class="form-actions">
		<button class="btn btn-primary btn_submit J_ajax_submit_btn"type="submit">下一步</button>
		<button type="button" class="btn" onclick="javascript:history.go(-1);">返回</button>
	</div>
	</form>
	</div>
	<script src="__ROOT__/statics/js/common.js"></script>
</body>
</html>